Maintain modifiers on Omit#31205
Conversation
|
It was nice to have a better error message with the name BTW, why |
| /** | ||
| * Construct a type with the properties of T except for those in type K. | ||
| */ | ||
| type Omit<T, K extends keyof any> = { |
There was a problem hiding this comment.
🤔Why can't this be K extends keyof T to make the type homomorphic?
There was a problem hiding this comment.
I don't believe that would make the type homomorphic, would it @ahejlsberg?
There was a problem hiding this comment.
Yeah, discussed offline, but for reasons outlined below, the fact that it's not just a simple keyof T or K (where K extends keyof T) means that TypeScript can't trivially look at that and say "yup, we gotta keep the modifiers around on this one".
There was a problem hiding this comment.
Could also do
type Omit<T, K extends keyof any> = T extends unknown ? Pick<T, Exclude<keyof T, K>> : never;that is to say: making the builtin Omit distributive. (Which'd give it an alias symbol, too) A bunch of library authors end up swapping their internal Omit to this once they get into situations involving unions.
Distributive conditional like this have perf issues when nested repeatedly right now, tho, sooooo.... ehhhhh?
What it comes down to is just the rules for when a mapped type decides it should maintain the modifiers, and right now it never does anything "smart" if the constraint (the thing after the
Yeah. I agree. ☹ |
|
@DanielRosenwasser is it planned to get this smart "in" in the near future ? |
|
I'm not sure what you're referring to - the functionality here was implemented. If you have a specific suggestion for new/different functionality in mapped types it's probably best to create a separate issue. |
|
I'm not sure what you're referring to - the changes here were merged and will be in TypeScript 3.5. If you have a specific suggestion for new/different functionality in mapped types it's probably best to create a separate issue. |
|
Sorry for the confusion... So you reverted the So my question is: will |
|
I think it is possible, but that change is not something I can personally dedicate a ton of time towards, and there are other possible changes that are more in-demand at the moment. |
Fixes #31190.